package com.poorstu.manager.impl;

import java.util.ArrayList;
import java.util.List;

import com.common.base.model.PaginationSupport;
import com.common.base.model.PublicFinalData;
import com.poorstu.dao.PartTimeDao;
import com.poorstu.dao.StudentDao;
import com.poorstu.manager.PartTimeManager;
import com.poorstu.model.LoginMod;
import com.poorstu.model.PartTimeMod;
import com.poorstu.model.RoleMod;
import com.poorstu.model.UserPartTimeMod;

public class PartTimeManagerImpl implements  PartTimeManager {
	
	PartTimeDao partTimeDao;
	StudentDao studentDao;

	public List<PartTimeMod> selectPartTimeALL() {
		
		return partTimeDao.selectPartTimeAll();
	}

	
	
	
	public boolean addPartTime(PartTimeMod partTime) {
		boolean b=false;
		try{
			b=partTimeDao.addPartTime(partTime);
			
		
		}catch(Exception e){
			e.printStackTrace();
		
		}
		return b;
	}

	
	


	

	public void delete(int[] jobId) {
		
		try{
		List<PartTimeMod> partList = new ArrayList<PartTimeMod>();
		for (int i = 0; i < jobId.length; i++) {
			PartTimeMod partTime = partTimeDao.selectPartTimeById(jobId[i]);
			partList.add(partTime);
		}
		partTimeDao.deletePartTime(partList);
		
	}catch(Exception e){
	e.printStackTrace();
	
	}
	}


	public PaginationSupport searchAllUserPartTimeByPage(int start) {
		// TODO Auto-generated method stub
		PaginationSupport ps=partTimeDao.getUserPartTimeByPage(null,null,null,start,PublicFinalData.ROLE_PAGE_MAX_SIZE);
try{
			
			List<UserPartTimeMod> newUserPartTimeList =new ArrayList<UserPartTimeMod>();
			List<UserPartTimeMod> userPartTimeList =new ArrayList<UserPartTimeMod>();
			
			userPartTimeList=ps.getItems();
			for(int i=0;i<userPartTimeList.size();i++){
				UserPartTimeMod up = new UserPartTimeMod();
				PartTimeMod partMod=new PartTimeMod();
			//	UserPartTimeMod uptm=new  UserPartTimeMod();
				
				partMod.setCompany(userPartTimeList.get(i).getPts().getCompany());
				partMod.setMoney(userPartTimeList.get(i).getPts().getMoney());
				//uptm.setParStatus(parStatus)
				LoginMod loginMod=new LoginMod();
				//循环到i=2时报错 数据设计问题
				loginMod.setName(userPartTimeList.get(i).getUser().getName());
			
				up.setParStatus(userPartTimeList.get(i).getParStatus());
				up.setUser(loginMod);
				up.setPts(partMod);
				up.setUspartId(userPartTimeList.get(i).getUspartId());
				newUserPartTimeList.add(up);
			}
			ps.setItems(newUserPartTimeList);
			 return ps;
		
		}catch(Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}




	public PartTimeMod selectPartTimeById(int jobId) {
		
		//List<UserPartTimeMod> userPartTimelist=studentDao.countApplyNumber(jobId);
		//int applyNumber=userPartTimelist.size();
		//studentDao.
		return partTimeDao.selectPartTimeById(jobId);
	}

	
	
	

//返回给学生申请助学岗位页，统计需求人数 申请人数  申请通过人数
	public UserPartTimeMod selectUserPartTimeId(int jobId) {
		List<UserPartTimeMod> userPartList=studentDao.countApplyNumber(jobId);
		int stuApply=userPartList.size();
		//int userPartTimeId=userPartList.get(0).getUspartId();
		
		int stuApplyPass=studentDao.countApplyPartTimeNumber(jobId).size();
		
		UserPartTimeMod uptm=new  UserPartTimeMod();
		uptm.setApplyNumber(stuApply);
		uptm.setApplyPassNumber(stuApplyPass);
			
		return uptm;
	
	}



	

	public List<PartTimeMod> selectPartTimeForTen() {
		
		PaginationSupport ps=partTimeDao.getPartTimeByPage( null, "leaTime", null, 0, 9);
		List<PartTimeMod> partTimeList=ps.getItems();
		return partTimeList;
	}




	public PaginationSupport searchAllPartTimeByPage(int start) {
		return partTimeDao.getPartTimeByPage(null,null,null,start,PublicFinalData.ROLE_PAGE_MAX_SIZE);
	}




	public boolean changePartTime(PartTimeMod partTime) {
		
		return partTimeDao.changePartTime(partTime);
	}




	public void setPartTimeDao(PartTimeDao partTimeDao) {
		this.partTimeDao = partTimeDao;
	}




	public void setStudentDao(StudentDao studentDao) {
		this.studentDao = studentDao;
	}
	
	

}
